import api from '../http/index'
import md5 from 'js-md5'

/* 用户登录 */
export const login = ({ userName, password, code }) => {
    const data = {
        userName,
        password: md5(password),
        code
    };
    return new Promise((resolve, reject) => {
        api.post('/api/Login/CheckLogin', data).then((res) => {
            resolve(res);
        }).catch(err => {
            reject(err)
        })
    })
};
/* 获取用户信息 - 导航 */
export const getMenuList = (res) => {
    const data = {
        roleid: res
    }
    return new Promise((resolve, reject) => {
        api.get(`/api/ClientsData/GetMenuDataJson`, data).then((res) => {
            resolve(res);
        }).catch(err => {
            reject(err)
        })
    });
};
/* 更新用户信息 */
export const updateUser = (data) => {
    return new Promise((resolve, reject) => {
        api.post('/api/User/PersonalSettings', data).then((res) => {
            resolve(res);
        }).catch(err => {
            reject(err)
        })
    })
};

/* 退出登录 */
export const logout = (res) => {
    const data = {
        uid: res
    }
    return new Promise((resolve, reject) => {
        api.get(`/api/Login/OutLogin`, data).then((res) => {
            resolve(res);
        }).catch(err => {
            reject(err)
        })
    });
};

/* 上传头像 */
export const uploadImage = (data) => {
    return new Promise((resolve, reject) => {
        api.post(`/api/User/UploadUserHead`, data).then((res) => {
            resolve(res);
        }).catch(err => {
            reject(err)
        })
    });
};

/* 模块权限 */
export const getModulePermission = (data) => {
    return new Promise((resolve, reject) => {
        api.get('/api/ClientsData/GetButtonDataJson', data).then((res) => {
            resolve(res);
        }).catch(err => {
            reject(err)
        })
    });
};

/* 修改密码 */
export const revisePassword = (data) => {
    const info = {
        id: data.id,
        password: md5(data.password),
        oldpassword: md5(data.oldpassword),
    };
    return new Promise((resolve, reject) => {
        api.post('/api/Login/RevisePassword', info).then((res) => {
            resolve(res);
        }).catch(err => {
            reject(err)
        })
    });
};

